//重置代理用户密码
$('.resetagentuserpwd').click(function(){
	$(this).blur();
	var agentId = $(this).attr("agent-sn");
	var data = {unionsn:$(this).attr("unionsn")};
	if( data.unionsn.length < 4){
		return errmsg("参数不正确");
	}
	if( confirm("确定要对代理账户【"+agentId+"】进行密码重置吗?") ){
		$.ajax({
			url:"/member/resetagentuserpwd.html",
			data: {data: genboxdata(data)},
			cache: false,
			async: false,
			type: "POST",
			dataType: 'json',
			success: function(data){
				if( data.status == 0 ){
					return errmsg(data.msg);
				}else{
					sucmsg(data.msg);
					window.location.reload();
					return false;
				}
			},
			error: function(){
				return errmsg("系统错误，请稍后重试或拨打官方客服电话进行反馈！");
			},
			complete: function (XHR, TS) {
				XHR = null;
			}
		})
	}
})
//重置代理用户账户禁用和启用
$('.changeaccountstatus').click(function(){
	$(this).blur();
	var agentId = $(this).attr("agent-sn");
	var disabledStatus = $(this).attr("disabled_status");
	var data = {unionsn:$(this).attr("unionsn")};
	if( data.unionsn.length < 4){
		return errmsg("参数不正确");
	}
	var action = '';
	if( disabledStatus == 0 ){
		action = "禁用";
	}
	if( disabledStatus == 1 ){
		action = "启用";
	}
	if( confirm("确定要将代理账户【"+agentId+"】设置为【"+action+"】吗?") ){
		$.ajax({
			url:"/member/changeaccountstatus.html",
			data: {data: genboxdata(data)},
			cache: false,
			async: false,
			type: "POST",
			dataType: 'json',
			success: function(data){
				if( data.status == 0 ){
					return errmsg(data.msg);
				}else{
					sucmsg(data.msg);
					window.location.reload();
					return false;
				}
			},
			error: function(){
				return errmsg("系统错误，请稍后重试或拨打官方客服电话进行反馈！");
			},
			complete: function (XHR, TS) {
				XHR = null;
			}
		})
	}
})
//删除代理账户
$('.delagentuser').click(function(){
	$(this).blur();
	var agentId = $(this).attr("agent-sn");
	var data = {unionsn:$(this).attr("unionsn")};
	if( data.unionsn.length < 4){
		return errmsg("参数不正确");
	}
	if( confirm("确定要将代理账户【"+agentId+"】删除吗?") ){
		$.ajax({
			url:"/member/delagentuser.html",
			data: {data: genboxdata(data)},
			cache: false,
			async: false,
			type: "POST",
			dataType: 'json',
			success: function(data){
				if( data.status == 0 ){
					return errmsg(data.msg);
				}else{
					sucmsg(data.msg);
					window.location.reload();
					return false;
				}
			},
			error: function(){
				return errmsg("系统错误，请稍后重试或拨打官方客服电话进行反馈！");
			},
			complete: function (XHR, TS) {
				XHR = null;
			}
		})
	}
})

// 添加代理遮罩层
$('#addagent').click(function(){
	$('.addagentBox').show();
})
// 取消添加代理
$('.cancelAddagentBox').click(function(){
	$('.addagentBox').hide();
	$("#user_name").val("");
	$("#user_mobile").val("");
})
//添加代理用户
$("#addAgentBtn").click(function (){
	$(this).blur();
	var data = {username:$("#user_name").val(),usermobile:$("#user_mobile").val()};
	if( data.username.length < 4 ){
		return errmsg("用户名太过简单！");
	}
	if( data.username.length > 15 ){
		return errmsg("用户名超长，请控制在15个字符以内！");
	}
	//验证手机号是否正确
	var flex = /^[1][3-9][0-9]{9}$/;
	if( flex.test(data.usermobile) == false ){
		return errmsg("手机号码格式不正确！");
	}
	$.ajax({
		url   : '/member/addagentuser',
		data  :{data: genboxdata(data)},
		cache : false,
		async : false,
		type  : "POST",
		dataType : 'json',
		success  : function (result){
			if(result.status == 0){
				return errmsg(result.msg);
			}else{
				sucmsg(result.msg);
				window.location.reload();
				return false;
			}
		}
	});
})
//审核代理的认证资料
$('.checkidcardstatus').click(function(){
	//资料赋值
	var zheng = $(this).attr("card-zheng");
	var fan = $(this).attr("card-fan");
	var unionsn = $(this).attr("unionsn");
	$("#idCardZheng").attr("href",zheng);
	$("#idCardZhengImg").attr("src",zheng);
	$("#idCardFan").attr("href",fan);
	$("#idCardFanImg").attr("src",fan);
	$("#idCardCheckUnionsn").val(unionsn);
	$('.idCardCheckBox').show();
})
//取消审核代理的认证资料
$('.cancelIdCardCheckBox').click(function(){
	$('.idCardCheckBox').hide();
	$("#idCardZheng").attr("href","javascript:void(0);");
	$("#idCardZhengImg").attr("src","#");
	$("#idCardFan").attr("href","javascript:void(0);");
	$("#idCardFanImg").attr("src","#");
	$("#check_remark").val("");
	$("#idCardCheckUnionsn").val("");
})
//进行审核操作
$(".subIdCardCheckBtn").click(function (){
	$(this).blur();
	var data = {unionsn:$("#idCardCheckUnionsn").val(),checkstatus:parseInt($(this).attr("id")),check_remark:$("#check_remark").val()};
	if( data.unionsn.length < 4){
		return errmsg("参数不正确");
	}
	if( data.checkstatus != 2 && data.checkstatus != 3 ){
		return errmsg("审核状态不正确！");
	}
	if( data.checkstatus == 3 && ( data.check_remark.length < 4 || data.check_remark.length > 20) ){
		return errmsg("拒绝审核，审核原因请控制在4-20个字符！" + data.check_remark.length);
	}
	$.ajax({
		url   : '/member/checkagentidcardstatus',
		data  :{data: genboxdata(data)},
		cache : false,
		async : false,
		type  : "POST",
		dataType : 'json',
		success  : function (result){
			if(result.status == 0){
				return errmsg(result.msg);
			}else{
				sucmsg(result.msg);
				window.location.reload();
				return false;
			}
		}
	});
})